This is a script allowing appends to a number of VoodooPad pages
from Quicksilver using a keyword at the beginnning of an entry.
I use it for quickly adding information on the fly to any of a
number of lists without switching window focus and not maintaining
several text files.

It's here in case anyone else might find it (or parts of it) useful.

Please feel free to make changes if you have ideas or can improve on my limited scripting ability.

--Quicksilver Append to VoodooPad.scpt
--Version 0.21 (2005-11-16)

IMPORTANT: This script MUST be modified in at least one place for it to work successfully. At a minimum, the values of the VPDoc and VPDocPath variables defined below must be modified to point to an existing VoodooPad file and its full path. Additionally, the triggers and pages in the big if block below should be modified to suit the particular desires of the user. Note that the page targets defined in the if block below must exist when the script is invoked. If they do not, data sent to those pages will be lost. At a bare minimum, the user should add a "Log" page to the target VoodooPad document to catch default log entries.

—Purpose: This script works with the applications VoodooPad from Flying Meat Inc. and Quicksilver from Blacktree, Inc. Both must be installed for the script to work. It links the two to allow rapid-fire appends to VoodooPad pages by using a keyword of one or more letters at the beginning of a Quicksilver input string.

—Installation: The script should be installed in a scripts folder. Note, however, that the script does not work if called directly from the scripts menu; it only works when invoked via Quicksilver with a "Process Text" action. Setting up a Quicksilver trigger that calls the script plus a "Process Text" action to allow one-keystroke access to the append command line is recommended.

—Usage: The text input expected is a keyword plus a text string to add to the page. In the if block below, Quicksilver input string of "gr ice cream" would add "ice cream" to the "Groceries" page in Quicksilver. This generally occurs in the background without distracting the user from the current work. If a keyword is used by itself as input, however, it brings the corresponding VoodooPad page to the front of the current windows for input. If no keyword is recognized, the entire text is appended with a timestamp to the "Log" page.

—Declare globals
global InputKeyword, InputString, VPDocPath, VPDoc

—Grab the input string from Quicksilver.
using terms from application "Quicksilver"
on process text QSInputString
—The following global variables point to the VoodooPad document to which Quicksilver should append, and that VoodooPad document specified with its full path. They should be changed by the user to match their preferred VoodooPad document and path.
set VPDoc to "main.vdoc"
set VPDocPath to "BB HD:Users:sample:Documents:VoodooPad:main.vdoc"

—Copy Quicksilver input string to global InputString. The first word of InputString is InputKeyword which will be tested in the big if block below, and clipped (if specified) in the VPAppend handler.
set InputString to QSInputString
set InputKeyword to first word of InputString
—The big if block. Essentially, it tests InputKeyword against lists of possible keywords for a particular page or list, and calls VPAppend with parameters matching how that list should be treated. The syntax is pretty straightforward: the list of strings in brackets in the if-clause are all the possible keywords that will trigger sending the input to the page specified in the PageName parameter in the then-clause. If a keyword is used in two different if clauses, the first clause will be the destination.

—ClipKeyword: Calling the handler with ClipKeyword will remove the first word from the input string before appending (so lists do not have various abbreviations before each entry if not desired).

—LogStyle: Calling the handler with LogStyle will append a full date and timestamp before the input string for time-sensitive entries.

IMPORTANT: The page specified in PageName MUST already exist in the target VoodooPad document. Entries will be lost if not.

if InputKeyword is in {"g", "gr", "gl", "groceries", "groc", "food"} then
VPAppend with ClipKeyword without LogStyle given PageName:"Groceries"
else if InputKeyword is in {"id", "idea", "ideas"} then
VPAppend with ClipKeyword without LogStyle given PageName:"Ideas"
else if InputKeyword is in {"ln", "link", "links"} then
VPAppend with ClipKeyword and LogStyle given PageName:"Links"
else if InputKeyword is in {"n", "note", "notes"} then
VPAppend with ClipKeyword without LogStyle given PageName:"Notes"
else if InputKeyword is in {"s", "sc", "scr", "scratch"} then
VPAppend with ClipKeyword without LogStyle given PageName:"Scratch"
else if InputKeyword is in {"w", "wishlist", "wish"} then
VPAppend with ClipKeyword without LogStyle given PageName:"Wishlist"
else if InputKeyword is in {"log", "l"} then
VPAppend with ClipKeyword and LogStyle given PageName:"Log"
else
—Default action: if the first word of the input string is not recognized as a keyword, prepend "log" to the input string so that it is processed by the VPAppend handler as a log entry, then call the VPAppend handler. The prepend is necessary so that input of a single non-keyword doesn't automatically bring up the log.
set InputString to "log" & space & InputString
VPAppend with ClipKeyword and LogStyle given PageName:"Log"
end if
end process text
end using terms from

—VPAppend handler. Takes the string PageName to which input should be directed, plus booleans LogStyle and ClipKeyword to define how the input string should be modified. Actions of LogStyle and ClipKeyword are described below.
on VPAppend given PageName:PageName, LogStyle:LogStyle, ClipKeyword:ClipKeyword
tell application "VoodooPad"
—Check to see whether document is already open. If not, open it.
if not (exists document named VPDoc) then
open VPDocPath
end if
—If only nonwhitespace and nonpunctuation input is the keyword, then bring document to the front for input, open corresponding page, move cursor to the bottom of the page, and return
ignoring white space and punctuation
if InputKeyword is InputString then
tell application "Finder" to activate document VPDoc of application "VoodooPad"
open page document VPDoc with title PageName
—This is a little hack to deal with VoodooPad's placing the cursor at the bottom of text on pages with 100 characters or fewer, but at the very top of all text on pages with more than 100 characters, when "open page" is called. This sends a Command-DownArrow to the page to place the insert point at the bottom of the page. Replacing "ASCII character 31" with "ASCII Character 30" below would cause the cursor to be placed at the top of the page, if that is preferred.
tell application "System Events" to keystroke (ASCII character 31) using command down
return
end if
end ignoring

—Process ClipKeyword: If true, delete the keyword from the append string (i.e., get second word through to the end of the string).
if ClipKeyword then
set AppendString to text from word 2 to last word in InputString
else
set AppendString to InputString
end if

—Process LogStyle: If true, prepend timestamp to the string
if LogStyle then
set AppendString to short date string of (current date) & space & time string of (current date) & ":" & space & AppendString
end if

—Finally, append the text and a return character to the selected page.
append text AppendString & return to page PageName of document VPDoc
end tell
end VPAppend